/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
 */

class UnusedLocalVariableCase {
    {
        int k = 12; // violation, assign and update but never use 'k'
        k++;
    }

    int a;
    UnusedLocalVariableCase(int a) { // ok, as 'a' is a constructor parameter not a local variable
        this.a = 12;
    }

    void method(int b) {
        int[] arr = {1, 2, 3};  // violation, unused local variable 'arr'
        int[] anotherArr = {1}; // ok, 'anotherArr' is accessed
        anotherArr[0] = 4;
    }

    String convertValue(String newValue) {
        String s = newValue.toLowerCase(); // violation, unused local variable 's'
        return newValue.toLowerCase();
    }

    void read() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s; // violation, unused local variable 's'
        while ((s = reader.readLine()) != null) {}
        try (BufferedReader reader1 = // ok, 'reader1' is a resource
                     new BufferedReader(new FileReader("abc.txt"))) {}
        try {
        } catch (Exception e) { // ok, 'e' is an exception parameter
        }
    }

    void loops() {
        int j = 12;
        for (int i = 0; j < 11; i++) { // violation, unused local variable 'i'
        }
        for (int p = 0; j < 11; p++)   // ok, 'p' is used
            p /= 2;
    }

    void lambdas() {
        Predicate<String> obj = (String str) -> true; // ok, 'str' is a lambda parameter
        obj.test("Test");
    }
}